/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef PLIOPORTMANAGER_H
#define PLIOPORTMANAGER_H

#include <lib/kvector.h>
#include <machine/pc/ioport.h>
#include <cstddef>

#include <tools/PLSingleton.h>
using namespace PLSDK;

/**
 * Manager for all io ports.
 */
class PLIOPortManager : public PLSingleton<PLIOPortManager> {
	friend class PLSingleton<PLIOPortManager>;
public:
	/**
	 * Allocate a number of successive I/O ports.
	 *
	 * @note This is normally called from an IoPort object.
	 * @param port pointer to the I/O port range object.
	 * @param ioPort the I/O port number.
	 * @param size the number of successive I/O ports - 1 to allocate.
	 * @return true, if the I/O port has been allocated successfull, false otherwise.
	 */
	bool allocate(PLIOPort *port, uint32_t ioPort, size_t size);
	/**
	 * Free a number of successive I/O ports.
	 *
	 * @note This is normally called from an IoPort object.
	 * @param port pointer to the I/O port range object.
	 */
	void free(PLIOPort *port);
protected:
	/**
	 * Constructor.
	 */
	PLIOPortManager();
private:
	virtual ~PLIOPortManager();
	PLIOPortManager(const PLIOPortManager &);
	PLIOPortManager &operator = (const PLIOPortManager &);
	PLKVector<PLIOPort *> m_usedIOPorts;
};

#endif
